<?php
require 'inc_security.php';

$list = new dataGrid('tpl_id',30);
$list->add('tpl_name','Giao diện','string',1,1, 'width="120px"');
$list->add('','Status','string');
$list->add('','Active','string');
$list->add('','Edit','edit');
$list->add('','Delete','delete');
$db_count = new db_count('SELECT count(*) as count 
                            FROM '.$bg_table.'
                            WHERE 1 
                            ');
$total = $db_count->total;unset($db_count);

$db_listing = new db_query('SELECT * 
                            FROM '.$bg_table.'
                            WHERE 1 '.$list->sqlSearch().'
                            ORDER BY '.$list->sqlSort().' tpl_id DESC
                            '.$list->limit($total));
$total_row = mysql_num_rows($db_listing->result);
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="vi" lang="vi" xmlns:og="http://ogp.me/ns#" xmlns:fb="https://www.facebook.com/2008/fbml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <?=$load_header?>
</head>
<body>
<div class="module_header bold fix"><?=$module_name?></div>
<div id="wrapper">
    <?=$list->showHeader($total_row)?>
    <?php
    $i = 0;
    ?>
    <?php while($row = mysql_fetch_assoc($db_listing->result)){
        $i++;
        $not_exists = false;
        //Kiểm tra tồn tại
        if(file_exists($bg_filepath . $row[$name_field])){
            $not_exists = true;
        }
        ?>
        <?=$list->start_tr($i,$row[$id_field])?>
        <td class="center"><?=$row['tpl_name']?></td>
        <td class="center"><?
            if($not_exists) echo '<span class="label label-success">OK</span>';
            else {
                echo '<span class="label label-important">Không tồn tại</span>&nbsp;&nbsp;<a class="create-tpl" href="#">Tạo thư mục</a>';
            }
            ?>
        </td>
        <?=$list->showCheckbox('tpl_active',$row['tpl_active'],$row[$id_field])?>
        <?=$list->showEdit($row[$id_field])?>
        <?=$list->showDelete($row[$id_field])?>
        <?=$list->end_tr()?>
    <?}?>
    <?=$list->showFooter()?>
</div>
</body>
</html>